package com.chanjiedata.changbs.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.proto.Mystock;
import com.chanjiedata.changbs.view.CustomCircleProgressBar;

import java.text.DecimalFormat;
import java.util.List;

/**
 * 文件名 : ProgressAdapter
 * 创建者 : MangoWang
 * 创建日期 : 2019/11/25 11:50
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */

public class MyBusinessAdapter extends BaseQuickAdapter<Mystock.listOfMyBusiness.List,BaseViewHolder> {
    public MyBusinessAdapter(Context context, List<Mystock.listOfMyBusiness.List> itemList) {
        super(R.layout.item_my_business,itemList);
    }

    @Override
    protected void convert(BaseViewHolder helper, Mystock.listOfMyBusiness.List item) {

        CustomCircleProgressBar amProgressbar = helper.getView(R.id.am_progressbar);
        helper.setText(R.id.tv_shop_name,item.getInfo().getMerchantName());
        String target_price = item.getTargetPrice();
        String Lg_av_amount = item.getLgAvAmount();
        String lineCard_amout = item.getLineCardAmout();
        double aDouble1 = Double.valueOf(Lg_av_amount);
        double aDouble2 = Double.valueOf(target_price);
        double aDouble3 = Double.valueOf(lineCard_amout);
        formatDouble(helper.getView(R.id.tv_money), aDouble1);
        helper.setText(R.id.tv_sn_number,item.getInfo().getSnCode())
                .setText(R.id.tv_name,item.getInfo().getGoodsName())
                .setText(R.id.tv_time,item.getInfo().getActicationTime())
                .setText(R.id.tv_dabiao_time,item.getInfo().getLineFullRefundTime())
                .setText(R.id.tv_total_jiao_yi,"¥ " + item.getTradingAmount());
        double fenshu = aDouble3 / aDouble2;
        double fenshu1 = fenshu * 100;
        int fenmu;
        if (0 < fenshu1 && fenshu1 < 1) {
            fenmu = 1;
        } else {
            fenmu = (int) fenshu1;
        }
        if (fenmu >= 100) {
            helper.setVisible(R.id.iv_yifan,true);
            helper.setVisible(R.id.am_progressbar,false);
            if (item.getInfo().getLineFullRefund().equals("0")) {
                helper.setBackgroundRes(R.id.iv_yifan,R.mipmap.dabiao);
            } else {
                helper.setBackgroundRes(R.id.iv_yifan,R.mipmap.yifan);
            }
        } else {
            helper.setVisible(R.id.iv_yifan,false);
            helper.setVisible(R.id.am_progressbar,true);
            if (aDouble3 > 10000) {
                double n =  aDouble3 / 10000;
                DecimalFormat decimalFormat = new DecimalFormat("0.00");
                amProgressbar.setProgressText(decimalFormat.format(n) + "万");
            } else {
                amProgressbar.setProgressText(lineCard_amout);
            }
            amProgressbar.setProgress(fenmu);
        }

        if(item.getIsExpire().equals("1"))
        {
            helper.setVisible(R.id.iv_yifan,true);
            amProgressbar.setVisibility(View.GONE);
            helper.setBackgroundRes(R.id.iv_yifan,R.mipmap.yiguoqi);
        }
    }

    private void formatDouble(TextView view, double value) {
        DecimalFormat decimalFormat = new DecimalFormat("0.00");

        if (value >= 10000) {
            double n = value / 10000;
            view.setText("¥ " + decimalFormat.format(n) + "万");
        } else {
            view.setText("¥ " + decimalFormat.format(value));
        }
    }
}